package com.auto.learning.activity;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import com.auto.learning.R;
import com.auto.learning.event.Handle;
import com.auto.learning.net.HttpRequestHelper;
import com.auto.learning.tools.CommonMethod;
import com.auto.learning.view.SharedPreferencesUtils;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

public class MyMessageReplyActivity extends Activity {

	private TextView tv_action_left,title,tv_action_right;
	private EditText et_message;
	int remindId, replyId;
	
	private Handle handle = new Handle(this){
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case HttpRequestHelper.GETDATA_SUCCESS:
				CommonMethod.makeNotice(MyMessageReplyActivity.this, "回复成功");
				finish();
				break;
			case HttpRequestHelper.GETDATA_FAIL:
				CommonMethod.makeNotice(MyMessageReplyActivity.this, msg.obj.toString());
				break;
			}
		};
	};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.my_message_reply_activity);
		initView();
	}
	
	
	public void initView(){
		Intent intent = getIntent();
		remindId = intent.getIntExtra("remindId", 0);
		replyId = intent.getIntExtra("replyId", 0);
		et_message = (EditText) findViewById(R.id.et_message);
		et_message.setHint("回复内容...");
		tv_action_left = (TextView) findViewById(R.id.tv_action_left);
		tv_action_right = (TextView) findViewById(R.id.tv_action_right);
		title = (TextView) findViewById(R.id.title);
		title.setText("回复评论");
		tv_action_right.setText("回复");
		tv_action_left.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		tv_action_right.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String content = et_message.getText().toString();
				if (TextUtils.isEmpty(content)) {
					CommonMethod.makeNotice(MyMessageReplyActivity.this, "回复内容不能为空");
					return;
				}
				replyComment(content);
			}
		});
	}
	
	public void replyComment(String msg){
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(HttpRequestHelper.USERID, String.valueOf(SharedPreferencesUtils.getParam(this, HttpRequestHelper.USERID, 0))));
		params.add(new BasicNameValuePair("reply", String.valueOf(msg)));
		params.add(new BasicNameValuePair("remindId", String.valueOf(remindId)));
		params.add(new BasicNameValuePair("replyId", String.valueOf(replyId)));
		HttpRequestHelper.executeHttpData(this, HttpRequestHelper.REMIND_REPLY, params, handle, HttpRequestHelper.GETDATA_SUCCESS, HttpRequestHelper.GETDATA_FAIL);
	}
}
